package com.taomeishu.mailcrazy.checkers.cn21;

import com.taomeishu.mailcrazy.CheckResult;
import com.taomeishu.mailcrazy.Mail;
import com.taomeishu.mailcrazy.http.ClientResponse;
import com.taomeishu.mailcrazy.parser.ResultParseException;
import com.taomeishu.mailcrazy.parser.ResultParser;

public class Cn21ResultParser implements ResultParser {

	@Override
	public CheckResult parse(ClientResponse clientResponse, String username, String domainName) throws ResultParseException {
		String s = (new String(clientResponse.getData())).trim();
		CheckResult result = new CheckResult(true);
		Mail mail = new Mail(username, domainName);
		result.setMail(mail);
		if (s.equals("0")) {
			result.addNotExistMail(mail);
		} else if (s.equals("-2")) {
			// exist
			result.addExistMail(mail);
		} else {
			throw new ResultParseException("other 21cn result code:" + s + " for " + username);
		}
		return result;
	}

}
